<?php

/**
 * Contains the Application_Form_AddUser class
 * @author Alexander Loewen
 * @version 0.1
 */

/**
 * handles the AddUser form
 * @package forms
 */
class Application_Form_User extends Zend_Form
{
    /**
     * init sets the form elements
     */
    public function init()
    {
	$this->setMethod('post');
	//$decorator = new My_Decorator_SimpleInput();

	/** 
	 * adds the username element
	 */
	$this->addElement('text', 'forename', array(
	    'label'      => 'Vorname:*',
	    'required'   => true,
	    'filters'    => array('StringTrim'),
	    'validators' => array(
		array('validator' => 'StringLength', 'options' => array(0, 50)),
		array('validator' => 'regex', 'options' => array('~^[A-ZÄÖÜa-zäöüß]+([-, ][A-ZÄÖÜa-zäöüß]+)*$~i',
			'messages'=>' %value% ist nicht erlaubt. Erlaubte Zeichen: a-z, äüöß,  , - '))
	    )
	));

	/**
	 * adds the name element
	 */
	$this->addElement('text', 'surname', array(
	    'label'      => 'Nachname:*',
	    'required'   => true,
	    'filters'    => array('StringTrim'),
	    'validators' => array(
		array('validator' => 'StringLength', 'options' => array(0, 75)),
		array('validator' => 'regex', 'options' => array('~^[A-ZÄÖÜa-zäöüß]+([-, ][A-ZÄÖÜa-zäöüß]+)*$~i',
			'messages'=>' %value% ist nicht erlaubt. Erlaubte Zeichen: a-z, äüöß,  , - '))
	    )
	));
	
	/**
	 * adds the email element
	 */
	$this->addElement('text', 'email', array(
	    'label'      => 'E-Mail:*',
	    'required'   => true,
	    'filters'    => array('StringTrim'),
	    'validators' => array(
		array('validator' => 'EmailAddress'),
		array('validator' => 'Db_NoRecordExists', false, 'options' => array('table' => 'person', 'field' => 'email')),
		array('validator' => 'StringLength', 'options' => array(0, 50))
	    )
	));

	/**
	 * adds the phone element
	 */
	$this->addElement('text', 'telnumber', array(
	    'label'	 => 'Telefon:',
	    'required'	 => false,
	    'filters'    => array('StringTrim'),
	    'validators' => array(
		array('validator' => 'StringLength', 'options' => array(0, 25)),
		array('validator' => 'regex', 
		    'options' => array('~^(\+)?(\([0-9]+\)\-?\s?)*([-, ,/]?[0-9])+([-, ,/][0-9]+)*$~i', 
			'messages'=>' %value% ist keine erlaubte Telefonnummer. Erlaubte Zeichen: z.B.: +49,(+49) [-, /,  ] Vorwahl [-, /,  ] Nummer')
	    ))
	));
	
	/**
	 * adds the form_of_employment element
	 */
	$this->addElement('select', 'form_of_employment', array(
	    'label'	 => 'Arbeitsform:',
	    'decorator'	 => 'ViewHelper',
	    'size'	 => '0',
	    'required'	 => true,
	    'multioptions' => array('Vollzeit' => 'Vollzeit', 'Teilzeit' => 'Teilzeit', 'Aushilfe' => 'Aushilfe')
	));
	
	/**
	 * adds the password element
	 */
	$this->addElement('password', 'password', array(
	    'label'      => 'Passwort:*',
	    'required'   => true,
	    'obscure'    => true,
	    'filters'    => array('StringTrim'),
	    'validators' => array(
		array('validator' => 'StringLength', 'options' => array(6, 20)),
		array('validator' => 'NotEmpty')
	    )
	));
	
	/**
	 * adds the password confirm element
	 */
	
	$this->addElement('password', 'confirm_password', array(
	    'label'      => 'Passwort bestätigen:*',
	    'required'   => true,
	    'filters'    => array('StringTrim'),
	    'ignore'	 => true,
	    'validators' => array(
		array('validator' => 'StringLength', 'options' => array(6, 20)),
		array('validator' => 'NotEmpty'),
		array('validator' => 'Identical', false, 'options' => array('token' => 'password'))
	    )
	));
	
	/**
	 * adds the admin(y,n) element
	 */
	$this->addElement('checkbox', 'is_admin', array(
	    'label'      => 'Administrator?:',
	    'required'   => false,
	    'checkedValue'   => 'Y',
	    'uncheckedValue' => 'N'
	));
	
	/**
	 * adds the submit button
	 */
	$this->addElement('submit', 'submit', array(
	    'ignore'   => true,
	    'label'    => 'Benutzer eintragen',
	));
    }
}
